/**
 * 
 */
package com.meiwenhui.sishuwujing.adapter;

import java.util.List;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.meiwenhui.sishuwujing.R;
import com.meiwenhui.sishuwujing.entities.Chapter;

public class ChapterAdapter extends BaseAdapter {

	private Context context;
	private List<Chapter> chapters;

	private LayoutInflater inflater;

	public ChapterAdapter(Context context, List<Chapter> chapters) {
		super();
		this.context = context;
		this.chapters = chapters;
		inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
	}

	public void addItems(List<Chapter> list) {
		chapters.addAll(list);
	}

	@Override
	public int getCount() {
		return chapters.size();
	}

	@Override
	public Object getItem(int position) {
		return chapters.get(position).getName();
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		TextView textView = null;
		if (convertView == null) {
			convertView = inflater.inflate(R.layout.activity_chapter_listview_item, null);
		}
		textView = (TextView) convertView.findViewById(R.id.chapter_item);
		textView.setText(chapters.get(position).getName());
		textView.setTag(chapters.get(position));
		return textView;
	}

}
